package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @ClassName:
 * @Description:
 * @version: v1.1.0
 * @author: shuaiqin
 * @date: 2021/9/18-15:56
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2021/9/18          shuaiqin          v1.1.0               修改原因
 */
@RestController
public class PaymentController {
    @Value("${server.port}")
    private String serverPort;
    public static HashMap<Long, Payment> hashMap = new HashMap<>();
    static {
        hashMap.put(1L,new Payment(1L,"11111111111111111111111111"));
        hashMap.put(2L,new Payment(1L,"22222222222222222222222222"));
        hashMap.put(3L,new Payment(1L,"33333333333333333333333333"));
    }
    @GetMapping(value = "/payemntSQL/{id}")
    public CommonResult<Payment> paymentSQL(@PathVariable("id")Long id){
        Payment payment = hashMap.get(id);
        if(id==4){
            throw new RuntimeException("运行异常");
        }
        CommonResult<Payment> paymentCommonResult = new CommonResult<>(200,"from mysql ..."+serverPort,payment);
        return paymentCommonResult;
    }
}
